package com.dy.spring.controllers;

import com.dy.spring.client.StreamClient;
import com.dy.spring.entities.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangdeyao
 * @date 2019/7/2 15:51
 */
@RestController
public class MqReceiverController {

    @Autowired
    StreamClient streamClient;

    @GetMapping("/send")
    public String messageWithMQ(String message) {
        streamClient.output().send(MessageBuilder.withPayload(message).build());
        return "ok";
    }

    @GetMapping("/send/user")
    public String messageWithMQ(@RequestBody UserEntity userEntity) {
        streamClient.output().send(MessageBuilder.withPayload(userEntity).build());
        return "ok";
    }

}
